package 力扣._8014_循环增长使字符串子序列等于另一个字符串;

public class Solution2 {
    int getminindex(int i1, int i2) {
        int i;
        if (i1 == -1 && i2 == -1)
            i = -1;
        else if (i1 == -1 || i2 == -1)
            i = i1 == -1 ? i2 : i1;
        else
            i = Math.min(i1, i2);
        return i;
    }

    public boolean canMakeSubsequence(String str1, String str2) {
        //子序列需要连续，只要相对位置一样即可
        char[] t = new char[26];
        t[0] = 'z';
        for (int i = 1; i < 26; i++) {
            t[i] = (char) ('a' - 1 + i);
        }
        int i = 0;
        int i1 = str1.indexOf(str2.charAt(0), i);
        int i2 = str1.indexOf(t[str2.charAt(0) - 'a'], i);
        i = getminindex(i1, i2);
        int k, index;
        for (k = i, index = i; k - i < str2.length() && k < str1.length(); k++) {
            i1 = str1.indexOf(str2.charAt(k - i), index);
            i2 = str1.indexOf(t[str2.charAt(k - i) - 'a'], index);
            index = getminindex(i1, i2);
            if (index == -1)
                break;
            else
                index++;
        }
        return k - i == str2.length();
    }

    public static void main(String[] args) {
        boolean b = new Solution2().canMakeSubsequence("abcewfgwgragsrdfawerfawefeawgfrgfsdgeragredgargranefiuragfbriybcvieyraflerwgfvlaweiygfeawyifeywfvbcegafbyewfgiyawegfewifbagirgyaregriybfgiyrfgewifb;aiwebfa;fgdfyeeyfgbiawfybdfaiyegfoa;fefa", "adgrtgawerf");
        System.out.println(b);
        System.out.println(-1 % 26);
    }
}
